package com.test.designPattern.ch17;

/**
 * @ClassName NameRepository
 * @Description TODO
 * @Author 维康
 * @Date 2018/6/11 16:01
 * @Version 1.0
 **/
public class NameRepository implements Container {
    public String names[] = {"Robert" , "John" ,"Julie" , "Lora"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    /**
     * 实现具体的迭代
     */
    private class NameIterator implements Iterator {

        int index;

        @Override
        public boolean hasNext() {
            if(index < names.length){
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if(this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
